<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" style="overflow: hidden">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>${Title}</title>
<link rel="shortcut icon" href="${res}favicon.ico" type="image/x-icon" />
 <!--Basic Styles-->
<link href="../framework/css/font.css" rel="stylesheet" />
<link href="../framework/miniui/themes/material/miniui.css" rel="stylesheet" />
<link href="../framework/css/app.min.1.css" rel="stylesheet" type="text/css" />
<link href="../framework/css/app.min.2.css" rel="stylesheet" type="text/css" />
<script src="../framework/main.js" type="text/javascript"></script>
<style type="text/css">
    html, body{
        margin:0;padding:0;border:0;width:100%;height:100%;overflow:hidden;
    }    
    </style>
</head>
<ef:init method="MemberBranch.initDialog">
<body class="body-detail">
	<script>
		Page.onLoad(function(){
			mini.get('dg1').load({BranchInnerCode:$('#BranchInnerCode').val()});	
		});
		
		function addUser(){
			var BranchInnerCode = $('#BranchInnerCode').val();
			if (!BranchInnerCode) {
				top.mini.alert("请选择部门");
				return;
			}
			var diag = mini.open({
				width: 600,
				height : 500,
				title : "添加用户",
				url : "${ctx}mhr/resourceDialog.jhtml?BranchInnerCode="+BranchInnerCode,
				onLoad : function(){
				},
				onOk : addSave
			});
		}
		
		function addSave(){
			var form = $DW.mini.getForm('form2');
			form.validate();
			if(form.isValid() == false){
				return;
			}
			Server.sendRequest("CompanyResource.add",form.getData(),function(response){
				if(response.Status == 1){
					top.mini.showTips({content:response.Message,state:'success'});
					$D.close();
					mini.get('dg1').reload();
				}else{
					top.mini.warn(response.Message);
				}
			});
		}
		
		function editUser() {
			var row = mini.get('dg1').getSelected();
			if(!row){
				top.mini.alert("@{Framework.DataGrid.PleaseSelectFirst}");
				return;
			}
			var id = row.Member;
			var diag = mini.open({
				width: 600,
				height : 500,
				title : "编辑用户",
				url : "${ctx}mhr/resourceDialog.jhtml?ID="+id,
				onLoad : function(){
					$DW.mini.get('UserName').disable();
					$DW.mini.get('Mobile').disable();
					$DW.mini.get('Email').disable();
					$DW.mini.get('Password').setEmptyText("ceshiceshi");
				},
				onOk : editSave
			});
		}
		
		function editSave(){
			var form = $DW.mini.getForm('form2');
			form.validate();
			if(form.isValid() == false){
				return;
			}
			Server.sendRequest("CompanyResource.save",form.getData(),function(response){
				if(response.Status == 1){
					top.mini.showTips({content:response.Message,state:'success'});
					$D.close();
					mini.get('dg1').reload();
				}else{
					top.mini.warn(response.Message);
				}
			});
		}
		
		function gender(e) {
			if (e.record.Gender == 'M') {
				return "男";
			} else if (e.record.Gender == 'F') {
				return "女";
			}
		}
		
		function delUser() {
			var arr = mini.get('dg1').getSelectedValue();
			if(!arr||arr.length==0){
				top.mini.alert("@{Common.PleaseSelectToDeleteRowFirst}");
				return;
			}
			
			top.mini.confirm("确定要删除该企业用户？",function(action){
				if(action == "ok"){
					Server.sendRequest("CompanyResource.del", {IDs:arr.join()},function(response){
						if(response.Status == 1){
							top.mini.showTips({content:response.Message,state:'success'});
							mini.get('dg1').reload();
						}else{
							top.mini.warn(response.Message);
						}
					});
				}
			});
		}
		
		function doSearch() {
			var name = mini.get('SearchName').getValue().trim();
			mini.get("dg1").load({SearchName:name, BranchInnerCode:$('#BranchInnerCode').val()});
		}
		
	</script>
	
	<input class="mini-hidden" id="ID" value="${ID}" />
	<input class="mini-hidden" id="BranchInnerCode" value="${BranchInnerCode}" />
	<div class="row" style="padding:10px;">
		<div class="col-xs-12">
			<div class="card z-depth-1" style="margin-bottom:0;">
	              <div class="card-body">
	                <table class="table">
						<tbody>
							<tr><td width="30%" align="right">名称：</td><td>${Name}</td></tr>
							<tr><td width="30%" align="right">负责人：</td><td>${ManagerName}</td></tr>
							<tr><td width="30%" align="right">备注：</td><td>${Memo}</td></tr>
						</tbody>
					</table>
		        </div>
		    </div>
		</div>
	</div>
	
	<div class="mini-toolbar" style="margin:2px 10px;" id="toolbar1" plain="true">
		 <div class="pull-right">
			<input class="mini-textbox" id="SearchName" type="text" emptyText="请输入用户名或用户真实姓名" style="width:160px;"/>
		 	<button class="btn btn-default" id="Submitbutton" onClick="doSearch()"><i class="iconfont icon-search"></i></button>
		 </div>
	     <a id="addBtn" class="mini-button" iconCls="icon-active-user" onClick="addUser()" plain="true">添加用户</a>
	     <a id="editBtn" class="mini-button" iconCls="icon-edit" onClick="editUser()" plain="true">编辑用户</a>
	     <a id="removeBtn" class="mini-button" iconCls="icon-remove" onClick="delUser()" plain="true">删除用户</a>
	</div>
	
	<div class="mini-fit" style="padding:0 10px 10px 10px;">
		<div id="dg1" class="mini-datagrid z-depth-1" style="width:100%;height:100%;" method="CompanyResource.grid" idField="Member" multiSelect="true">
		    <div property="columns">
		       	<div type="indexcolumn"></div>
		        <div type="checkcolumn"></div>       
		        <div field="EmployeeNumber" width="12%">工号</div>
	            <div field="UserName" width="13%">用户名</div>
	            <div field="RealName" width="12%">真实姓名</div>
	            <div field="Gender" renderer="gender" width="12%">性别</div>
	            <div field="Mobile" width="12%">手机号</div>
	            <!-- <div field="" width="12%">所属岗位</div> -->
	            <div field="BranchName" width="40%">所属部门</div>
		    </div>
		</div>
	</div>
</body>
</ef:init>
</html>